package com.base.myproject.client.busi.system;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import com.base.myproject.client.busi.BaseStore;
import com.base.myproject.client.busi.JDBCModelData;
import com.base.myproject.client.busi.BO.BaseObject;
import com.base.myproject.client.busi.BO.BusiObject;
import com.base.myproject.client.jdbc.DataSet;
import com.base.myproject.client.jdbc.StoreInfo;
import com.base.myproject.client.system.SystemMessage;
import com.base.myproject.client.tools.SendServlet;
import com.base.myproject.client.ui.BaseFormPanel;
import com.base.myproject.client.ui.BaseGrid;
import com.base.myproject.client.ui.BaseInputDialog;
import com.base.myproject.client.ui.BaseJDBCPanel;
import com.extjs.gxt.ui.client.Style.HorizontalAlignment;
import com.extjs.gxt.ui.client.Style.LayoutRegion;
import com.extjs.gxt.ui.client.Style.Scroll;
import com.extjs.gxt.ui.client.Style.SelectionMode;
import com.extjs.gxt.ui.client.Style.VerticalAlignment;
import com.extjs.gxt.ui.client.data.ModelData;
import com.extjs.gxt.ui.client.data.ModelType;
import com.extjs.gxt.ui.client.event.BaseEvent;
import com.extjs.gxt.ui.client.event.ButtonEvent;
import com.extjs.gxt.ui.client.event.ComponentEvent;
import com.extjs.gxt.ui.client.event.Events;
import com.extjs.gxt.ui.client.event.Listener;
import com.extjs.gxt.ui.client.event.SelectionListener;
import com.extjs.gxt.ui.client.store.ListStore;
import com.extjs.gxt.ui.client.util.Margins;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.Info;
import com.extjs.gxt.ui.client.widget.TabItem;
import com.extjs.gxt.ui.client.widget.TabPanel;
import com.extjs.gxt.ui.client.widget.button.Button;
import com.extjs.gxt.ui.client.widget.form.CheckBox;
import com.extjs.gxt.ui.client.widget.form.FieldSet;
import com.extjs.gxt.ui.client.widget.form.TextField;
import com.extjs.gxt.ui.client.widget.grid.CellEditor;
import com.extjs.gxt.ui.client.widget.grid.CheckBoxSelectionModel;
import com.extjs.gxt.ui.client.widget.grid.CheckColumnConfig;
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
import com.extjs.gxt.ui.client.widget.grid.ColumnData;
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
import com.extjs.gxt.ui.client.widget.grid.Grid;
import com.extjs.gxt.ui.client.widget.grid.GridCellRenderer;
import com.extjs.gxt.ui.client.widget.layout.BorderLayout;
import com.extjs.gxt.ui.client.widget.layout.BorderLayoutData;
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
import com.extjs.gxt.ui.client.widget.layout.TableData;
import com.extjs.gxt.ui.client.widget.layout.TableLayout;
import com.extjs.gxt.ui.client.widget.toolbar.SeparatorToolItem;
import com.extjs.gxt.ui.client.widget.toolbar.ToolBar;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;

public class GroupMenber extends BaseJDBCPanel {

	BaseStore groupstore = null;
	static BaseStore busipermissionsstore = null;
	BaseStore<BusiObject> menustore;
	Button addnewgroupmenber = new Button("添加新组员");
	BaseStore groupmenberstore;
	BaseGrid groupmenbergrid ;
	public GroupMenber()
	{
		init();
		registerStore(groupstore);
		registerMainStore(groupstore);
		this.setHeight(400);
	}
	public void init() {
	
		BorderLayoutData centerData = new BorderLayoutData(LayoutRegion.CENTER);  
	    centerData.setMargins(new Margins(5, 5, 0, 0));  
		this.add(initWeiget(),centerData);
		getRender("bcode");
	}

	public ContentPanel initWeiget() {

		CheckBoxSelectionModel cbs = new CheckBoxSelectionModel();
		// cbs.setSelectionMode(SelectionMode.SIMPLE);
		List<ColumnConfig> columns = new ArrayList<ColumnConfig>();
		columns.add(cbs.getColumn());
		ColumnConfig groupcode = new ColumnConfig("groupicode", "组编码", 100);
		TextField<String> groupcodetext = new TextField<String>();
		groupcode.setEditor(new CellEditor(groupcodetext));
		columns.add(groupcode);

		ColumnConfig groupname = new ColumnConfig("groupname", "组名", 100);
		TextField<String> grouptext = new TextField<String>();
		groupname.setEditor(new CellEditor(grouptext));
		columns.add(groupname);

		ColumnModel cm = new ColumnModel(columns);

		ModelType type = new ModelType();
		type.setRoot("records");
		type.setRecordName("record");
		type.addField("groupicode");
		type.addField("groupname");

		StoreInfo info = new StoreInfo();
		info.setTablename("basegroup");
		info.setSql("select * from basegroup");
		info.setKeyname(new String[] { "groupicode","groupname"});
		groupstore = new BaseStore<JDBCModelData>(type, info);
		BaseGrid grid = new BaseGrid(groupstore, cm);
		cbs.setSelectionMode(SelectionMode.SINGLE);
		grid.setSelectionModel(cbs);
		grid.setAutoWidth(true);
		grid.setAutoHeight(true);

		BorderLayoutData westData = new BorderLayoutData(LayoutRegion.WEST, 250);
		westData.setSplit(true);
		westData.setCollapsible(true);
		westData.setMargins(new Margins(5));

		BorderLayoutData eastData = new BorderLayoutData(LayoutRegion.CENTER,
				150);
		eastData.setSplit(true);
		// eastData.setCollapsible(true);
		eastData.setMargins(new Margins(5));

		ContentPanel panel = new ContentPanel();

		panel.setLayout(new BorderLayout());

		ContentPanel panel1 = new ContentPanel();
		panel1.setLayout(new FitLayout());
		panel1.add(grid);
		panel.add(panel1, westData);

		TabPanel tabpanel = new TabPanel();
		tabpanel.setAutoHeight(true);
		tabpanel.setAutoWidth(true);
		TabItem normal1 = new TabItem("组成员");
		normal1.add(groupmenberPanel());
		TabItem normal2 = new TabItem("菜单权限");
		
		normal2.add(CreateMenuGrid());
		normal2.setScrollMode(Scroll.AUTO);
//		TabItem normal3 = new TabItem("业务权限");
//		VerticalPanel verticalpanel = new VerticalPanel();
//		verticalpanel.add(BusiPanel());
//		verticalpanel.add(CreateBusiForm());
//		
//		
//		normal3.add(verticalpanel);
		
		
		tabpanel.add(normal1);
		tabpanel.add(normal2);
//		tabpanel.add(normal3);
		panel.add(tabpanel, eastData);

		panel.setHeaderVisible(false);
		// 所有组织完成后，要注册store
		setMaincomponent(grid);
		registerMainStore(groupstore);
		this.registerStore(groupstore);
		panel.setScrollMode(Scroll.AUTO);
		return panel;
	}
	ColumnConfig bcode ;
	public ContentPanel groupmenberPanel() {
		CheckBoxSelectionModel cbs = new CheckBoxSelectionModel();
		List<ColumnConfig> columns = new ArrayList<ColumnConfig>();
		columns.add(cbs.getColumn());

		bcode = new ColumnConfig("bcode", "组成员代码", 100);
		TextField<String> bcodetext = new TextField<String>();
		bcode.setEditor(new CellEditor(bcodetext));
		columns.add(bcode);
//		ColumnConfig bname = new ColumnConfig("bname", "组成员名称", 100);
//		TextField<String> bnametext = new TextField<String>();
//		bname.setEditor(new CellEditor(bnametext));
//		columns.add(bname);

		ColumnModel cm = new ColumnModel(columns);

		ModelType type = new ModelType();
		type.setRoot("records");
		type.setRecordName("record");
		type.addField("groupicode");
		type.addField("bcode");
		type.addField("icode");

		StoreInfo info = new StoreInfo();
		info.setTablename("basegroupmenber");
		info.setSql("select icode, groupicode,bcode from basegroupmenber where groupicode='{groupicode}'");
		info.setForcenolimit("true");
		info.setKeyname(new String[] { "icode" });
		info.setParent(groupstore);
		info.setLinkparentcolumns(new String[] { "groupicode" }); // 关联主表字段
		info.setLinkparent_chile_columns(new String[] { "groupicode" });// 关联主表字段// (子表)
		groupmenberstore = new BaseStore<JDBCModelData>(type, info);
		
		groupmenbergrid = new BaseGrid(groupmenberstore, cm){
			 public void addnewrecord() {
				 addmenber();
			 }
			 public void deleterecord() {
				 super.deleterecord();
				 this.trysave();
			 }
		 }
		 ;
		 cbs.setSelectionMode(SelectionMode.SINGLE);
		 groupmenbergrid.setSelectionModel(cbs);
		 groupmenbergrid.setAutoWidth(true);
//		 groupmenbergrid.setAutoHeight(true);
		
		addnewgroupmenber.addListener(Events.Select, getListener());

		ContentPanel panel = new ContentPanel();

		panel.setHeaderVisible(false);

		
	
		 ToolBar toolBar = new ToolBar();  
		 toolBar.add(addnewgroupmenber);  
		 toolBar.add(new SeparatorToolItem());  
//		    toolBar.add(new Button("Remove", Resources.ICONS.delete()));  
//		    toolBar.add(new SeparatorToolItem());  
//		    toolBar.add(new Button("Configure", Resources.ICONS.plugin()));  
		panel.setLayout(new FitLayout());  
		panel.setTopComponent(toolBar);
		panel.add(groupmenbergrid);
		// 所有组织完成后，要注册store
		panel.setSize(600, 300);  
//		groupmenbergrid.setSize(600	, 200);
		//groupmenbergrid.setDeferHeight(true);
		groupmenbergrid.getView().setForceFit(true);
		//groupmenbergrid.setAutoHeight(true);
//		panel.setDeferHeight(true);
		this.registerStore(groupmenberstore);
		return panel;
	}
/**
 * 菜单
 * @return
 */
//	public ContentPanel MenuPanel() {
//		CheckBoxSelectionModel cbs = new CheckBoxSelectionModel();
//
//		List<ColumnConfig> columns = new ArrayList<ColumnConfig>();
//		columns.add(cbs.getColumn());
//
//		ColumnConfig menucode = new ColumnConfig("menucode", "菜单编号", 100);
//		TextField<String> menucodetext = new TextField<String>();
//		menucode.setEditor(new CellEditor(menucodetext));
//		columns.add(menucode);
//		ColumnConfig menuname = new ColumnConfig("menuname", "菜单名", 100);
//		TextField<String> menunametext = new TextField<String>();
//		menuname.setEditor(new CellEditor(menunametext));
//		columns.add(menuname);
//		ColumnConfig groupicode = new ColumnConfig("groupicode", "组", 100);
//		TextField<String> groupicodetext = new TextField<String>();
//		groupicode.setEditor(new CellEditor(groupicodetext));
//		columns.add(groupicode);
//
//		ColumnModel cm = new ColumnModel(columns);
//
//		ModelType type = new ModelType();
//		type.setRoot("records");
//		type.setRecordName("record");
//		type.addField("menucode");
//		type.addField("menuname");
//		type.addField("groupicode");
//
//		StoreInfo info = new StoreInfo();
//		info.setTablename("menupermissions");
//		info.setSql("select menucode,(select menuname from menu where menucode =menupermissions.menucode )as  menuname,groupicode from menupermissions");
//		info.setLinkparentcolumns(new String[] { "groupicode" });
//		info.setKeyname(new String[] { "groupicode","menucode"});
//		info.setSortcolumn("menucode");
//		BaseStore menupermissionsstore = new BaseStore<JDBCModelData>(type,
//				info);
//		BaseGrid grid = new BaseGrid(menupermissionsstore, cm);
//		
////		grid.setAutoWidth(true);
////		grid.setAutoHeight(true);
//		ContentPanel panel = new ContentPanel();
//		panel.setLayout(new FitLayout());
//		panel.add(grid);
//		panel.setSize(600, 300);  
//		grid.getView().setForceFit(true);
//		// 所有组织完成后，要注册store
//		menupermissionsstore.setNeedsave(false);
//		menupermissionsstore.setParent(groupstore);
////		不注册，不用默认保存
//		this.registerStore(menupermissionsstore);
//		return panel;
//	}
	/**
	 * 菜单数据
	 */
	void CreateMenuStore() {
		ModelType type = new ModelType();
		type.setRoot("records");
		type.setRecordName("record");

		type.addField("menucode");
		type.addField("menuname");
		type.addField("isset");
		type.getField("isset").setType(Boolean.class);
		// type.addField("Phone");
		// type.addField("imagepath");
		StoreInfo info = new StoreInfo();
		info.setTablename("menu");
		
		String sql = "select a.menucode,a.menuname,b.groupicode, ";
		sql +=		" (case when (b.groupicode is null) then '0' else '1' end )as isset ";
		sql +=	"  from  ";
		sql +=	" (";
		sql +=	" select * from menu "; 
		sql +=	" ) as a ";
		sql +=	" left join "; 
		sql +=	" ( ";
		sql +=	" select * from menupermissions  where groupicode ='{groupicode}' ";
		sql +=	" ) as b ";
		sql +=	" on a.menucode = b.menucode order by a.menucode";
		
		//info.setSql("select *,1 as isset from menu order by menucode");
		info.setSql(sql);
		info.setKeyname(new String[] { "icode" });
		info.setLinkparentcolumns(new String[] { "groupicode" }); // 关联主表字段
		info.setLinkparent_chile_columns(new String[] { "groupicode" });// 关联主表字段// (子表)
		info.setNeedAllRow("no");	
		info.setParent(groupstore);
		info.setForcenolimit("true");
		
		menustore = new BaseStore<BusiObject>(type, info);
		menustore.setParent(groupstore);
		menustore.setNeedsave(false);

//		menustore.setLinkparentcolumns(new String[]{"groupicode"});
//		menustore.setLinkparent_chile_columns(new String[]{"groupicode"});

	}
	/**
	 * 菜单界面
	 * @return
	 */
	BaseGrid<BusiObject> CreateMenuGrid() {
		CreateMenuStore();
		CheckBoxSelectionModel<BusiObject> cbs = new CheckBoxSelectionModel<BusiObject>();
		cbs.setSelectionMode(SelectionMode.MULTI);
		List<ColumnConfig> columns = new ArrayList<ColumnConfig>();
		// columns.add(cbs.getColumn());
		ColumnConfig menucode = new ColumnConfig("menucode", "菜单号", 100);
		TextField<String> menucodetext = new TextField<String>();
		menucode.setEditor(new CellEditor(menucodetext));
		columns.add(menucode);

		ColumnConfig cc2 = new ColumnConfig("menuname", "菜单名", 100);
		TextField<String> cctext2 = new TextField<String>();
		cc2.setEditor(new CellEditor(cctext2));
		columns.add(cc2);

		CheckColumnConfig checkColumn = new CheckColumnConfig("isset", "分配?",
				55);
		CellEditor checkBoxEditor = new CellEditor(new CheckBox());
		checkColumn.setEditor(checkBoxEditor);
		columns.add(checkColumn);

		ColumnModel cm = new ColumnModel(columns);
		BaseGrid<BusiObject> grid = new BaseGrid<BusiObject>(menustore, cm,
				false, false, null);
		// grid.setAutoHeight(true);
		// grid.setAutoWidth(true);
		grid.setStripeRows(true);
		// grid.setBorders(true);
//		grid.setHeight(SystemMessage.fullheightinmain);
//		grid.setWidth(SystemMessage.fullwidthinmain);
		grid.setAutoWidth(true);
		//grid.setAutoHeight(true);
		//grid.setSelectionModel(cbs);
		// grid.setStyleAttribute("borderTop", "none");
		// grid.setSelectionModel(new GridSelectionModel<BusiObject>());
		grid.addPlugin(checkColumn);
		grid.setSize(400, 300);
		grid.getView().setForceFit(true);
		// ---

		// checkColumn.addListener(Events., listener)
		return grid;
	}

	public ContentPanel BusiPanel() {
		CheckBoxSelectionModel cbs = new CheckBoxSelectionModel();

		List<ColumnConfig> columns = new ArrayList<ColumnConfig>();
		columns.add(cbs.getColumn());

		ColumnConfig busicode = new ColumnConfig("busicode", "业务编号", 100);
		
		columns.add(busicode);
		ColumnConfig businame = new ColumnConfig("businame", "业务名", 100);
	
		columns.add(businame);
		ColumnConfig groupicode = new ColumnConfig("groupicode", "组", 100);
		
		columns.add(groupicode);
		ColumnConfig premissionproperty = new ColumnConfig("premissionproperty", "属性", 100);
		
		columns.add(premissionproperty);

		ColumnModel cm = new ColumnModel(columns);

		ModelType type = new ModelType();
		type.setRoot("records");
		type.setRecordName("record");
		type.addField("busicode");
		type.addField("businame");
		type.addField("groupicode");
		type.addField("permissionsbcode");
		
		type.addField("premissionproperty");
		StoreInfo info = new StoreInfo();
		info.setTablename("busipermissions");
		info.setSql("select busicode,businame,groupicode,permissionsbcode,premissionproperty from busipermissions");
		info.setLinkparentcolumns(new String[] { "groupicode" });
		info.setKeyname(new String[] { "groupicode","busicode"});
		 busipermissionsstore = new BaseStore<JDBCModelData>(type,
				info);
		BaseGrid grid = new BaseGrid(busipermissionsstore, cm);
		grid.setAutoWidth(true);
		grid.setAutoHeight(true);
		ContentPanel panel = new ContentPanel();
		panel.setLayout(new FitLayout());
		panel.add(grid);
		panel.setHeight(400);
		// 所有组织完成后，要注册store

		busipermissionsstore.setParent(groupstore);
		this.registerStore(busipermissionsstore);
		return panel;
	}
	FieldSet CreateBusiForm()
	{ 
		
		BaseFormPanel leftbusiform = new BaseFormPanel(busipermissionsstore);
		BaseFormPanel rightbusiform = new BaseFormPanel(busipermissionsstore);
		
		
		
		TextField<String> busicode = new TextField<String>();
		busicode.setName("busicode");
		busicode.setAllowBlank(false);
		busicode.setFieldLabel("业务编码");
		
		TextField<String> businame = new TextField<String>();
		businame.setName("businame");
		businame.setAllowBlank(false);
		businame.setFieldLabel("业务名称");
		
		TextField<String> permissionsbcode = new TextField<String>();
		permissionsbcode.setName("permissionsbcode");
		permissionsbcode.setAllowBlank(false);
		permissionsbcode.setFieldLabel("可使用权限");
		
		
		
		ToolBar toolBar = new ToolBar();
		final Button addnewrow = new Button("添加新业务权限");
		addnewrow.addSelectionListener(new SelectionListener<ButtonEvent>(){

			@Override
			public void componentSelected(ButtonEvent ce) {
				// TODO Auto-generated method stub
				busipermissionsstore.add();
			}
			
		});
	
		toolBar.add(addnewrow);
		leftbusiform.setTopComponent(toolBar);
		leftbusiform.add(busicode);
		leftbusiform.add(businame);
		rightbusiform.add(permissionsbcode);
		
		
		leftbusiform.setBodyBorder(false);
		leftbusiform.setFrame(false);
		leftbusiform.setHeaderVisible(false);
		
		rightbusiform.setBodyBorder(false);
		rightbusiform.setFrame(false);
		rightbusiform.setHeaderVisible(false);
		
		
		
		
		leftbusiform.inited();
		rightbusiform.inited();
		
		TableData td = new TableData();
		td.setColspan(1);
		td.setRowspan(1);
		// 对齐方式
		td.setHorizontalAlign(HorizontalAlignment.LEFT);
		td.setVerticalAlign(VerticalAlignment.TOP);
		FieldSet fieldSet = new FieldSet();
		fieldSet.setHeading("业务权限设置");
		fieldSet.setLayout(new TableLayout(2));
		fieldSet.add(leftbusiform,td);
		fieldSet.add(rightbusiform,td);
		fieldSet.setAutoHeight(true);
		return fieldSet;
		
	}
	
	int sync = 0;                                                      
	Listener<BaseEvent> defaultlistener;                               
                                                                     
	Listener<BaseEvent> getListener() {                                
		if(defaultlistener!=null)                                        
		{                                                                
			return defaultlistener;                                        
		}                                                                
                                                                     
		defaultlistener = new Listener<BaseEvent>() {                    
			public void handleEvent(BaseEvent be) {                        
				sync++;                                                      
				try {                                                        
					if (sync == 1) {                                           
						if (be.getType() == Events.Select) {                     
							if (be.getSource().equals(addnewgroupmenber)) {   
								
								
								 addmenber();
								
////								bcode.setRenderer(renderer)        ;   
//////								groupmenbergrid.repaint();
////								groupmenbergrid.getView().refresh(true);
////								
//								getRender("bcode");
								
							}                                                      
						} else if (be.getType() == Events.Change) {              
							if (be.getSource().equals("")) {         
                                                                     
							}                                                      
						} else if (be.getType() == Events.KeyUp) {               
							if (be instanceof ComponentEvent) {                    
								if (((ComponentEvent) be).getKeyCode() == 13) // 回车
								{                                                    
								}                                                    
							}                                                      
						}                                                        
					}                                                          
				} finally {                                                  
					sync--;                                                    
				}                                                            
			}                                                              
                                                                     
		};                                                               
		return defaultlistener;                                          
	}      
	
	private void aa(String filter){
		List<ColumnConfig> bocodecolumns2 = new ArrayList<ColumnConfig>();
		ColumnConfig bcode2 = new ColumnConfig("code", "人员", 100);
		bcode2.setHidden(true);
		bocodecolumns2.add(bcode2);

		ColumnConfig employno = new ColumnConfig("employno", "雇佣编码", 100);
		bocodecolumns2.add(employno);
		
		ColumnConfig bname = new ColumnConfig("name", "人员名", 100);
		bocodecolumns2.add(bname);
		
		ModelType type = new ModelType();
		type.setRoot("records");
		type.setRecordName("record");
		type.setTotalName("totle");
		type.addField("code");
		type.addField("employno");
		type.addField("name");
		StoreInfo info = new StoreInfo();
		info.setTablename("bcode");
		info.setNeedAllRow("no");
		info.setSql("select bcode.bcode as code ,bcode.bname as name,bcode_job.employno as employno from bcode,bcode_job " +
				"where bcode.bcode=bcode_job.bcode and employstatus='在职'"+(filter.equals("")?"":(" and bcode.bcode not in ("+filter+")")));

		 BaseInputDialog bd =new BaseInputDialog(bocodecolumns2, type,info, "name", "code"){
			 public  void doposted(List<BusiObject> at) {
					for(BusiObject bo:at){
						System.out.println("code="+bo.get("code"));
						HashMap hm = new HashMap();
						hm.put("bcode", bo.get("code"));
						groupmenberstore.add(hm);
					}
					this.close();
					groupmenbergrid.getView().refresh(true);
				}
		 };
	 
	 bd.show();
	}
	
	GridCellRenderer<ModelData>	renderer = new GridCellRenderer<ModelData>() {

	      public String render(ModelData model, String property, ColumnData d, int rowIndex,
	          int colIndex, ListStore<ModelData> store, Grid<ModelData> grid) {

	       if(model.get(property)==null)
	        return "" ;

	       if(model.get(property).equals("999"))
	           return "" + ("<img src='images/baseimage/money_yen.png' />" );
	       else if(model.get(property).equals("0001"))
	       	   return "" + ("<img src='images/baseimage/icon-complete.gif' />" );
	       return "" + ("<img src='images/baseimage/cut.png'/>" );
	      // return SystemMessage.getstatus(model.get(property)+"");
	      }
	    };
	    
	public  void getRender(String column){
		if(column.equals("bcode"))
		{
			final com.base.myproject.client.tools.GreetingServiceAsync greetingService = GWT
			.create(com.base.myproject.client.tools.GreetingService.class);
			greetingService.getDataSet("select bcode,bname from bcode",new AsyncCallback<DataSet>(){

				@Override
				public void onFailure(Throwable caught) {
				Window.alert("网络连接错误");
					
				}

				@Override
				public void onSuccess(final DataSet result) {
					GridCellRenderer<ModelData>	renderer = new GridCellRenderer<ModelData>() {

					      public String render(ModelData model, String property, ColumnData d, int rowIndex,
					          int colIndex, ListStore<ModelData> store, Grid<ModelData> grid) {
					    	  
					    	  for(int i=0;i<result.getRowCount();i++)
					    	  {
					    		  if(model.get(property)==null)
					    			  return model.get(property);
					    		  else if(model.get(property).equals(result.getValue(i, "bcode")))
					    			  return result.getValue(i, "bname");
					    	  }
					    	  return model.get(property);
					      }
					    };
					    bcode.setRenderer(renderer)  ;
					    groupmenbergrid.getView().refresh(true);
					
				}
				
			});
			
	
			   
		}
		
	}
	private void addmenber(){
		int count =groupmenberstore.getCount();
		String filter ="";
		if (count > 0) {
			for (int i = 0; i < count; i++) {
				String bcode = groupmenberstore.getValue(i, "bcode")+ "";
				GWT.log(bcode, null);
				filter += "'" + bcode + "',";
			}
			filter = filter.substring(0, filter.length() - 1);
		}
		
		aa(filter);
	}
	/**
	 * 注意菜单的保存方式才用特殊做法。
	 */
	protected void save() {
	
		//super.save();
		groupstore.trySave();
		Object groupid = groupstore.getValue("groupicode");
		java.util.Vector<String> v = new java.util.Vector<String>();
		
		v.addAll(groupstore._trySave(groupstore.getCurcowindex()));
		
		for(int i=0;i<menustore.getCount();i++)
		{
			if((menustore.getAt(i).getBusistatus() & BaseObject.UPDATE) == BaseObject.UPDATE)
			{
				String sql = "";
				if(menustore.getValue(i, "isset").equals(Boolean.TRUE))
				{
					sql = "insert into menupermissions (menucode,groupicode) values('"
						+ menustore.getValue(i,"menucode") + "','" + groupid + "') ";
				}
				else
				{
					sql = " delete menupermissions where menucode='"
						+ menustore.getValue(i,"menucode") + "' and groupicode='" + groupid
						+ "'";
				}
				v.add(sql);
			}
		}
//		for (Record r : menustore.getModifiedRecords()) {
//			Debug.printf(r.get("menucode"), 4);
//			String sql = "";
//			if (r.get("isset").equals(Boolean.TRUE)) {
//				Debug.printf(r.get("menucode") + "  set", 4);
//				sql = "insert into menupermissions (menucode,groupicode) values('"
//						+ r.get("menucode") + "','" + groupid + "') ";
//
//			} else {
//				Debug.printf(r.get("menucode") + " cancel set", 4);
//				sql = " delete menupermissions where menucode='"
//						+ r.get("menucode") + "' and groupicode='" + groupid
//						+ "'";
//			}
//			v.add(sql);
//			Debug.printf(sql, 4);
//		}

		SendServlet ss = new SendServlet();
		ss.ExcJDBCSQL(v, new AsyncCallback<String>() {

			@Override
			public void onFailure(Throwable caught) {
				Info.display("", "保存失败");

			}

			@Override
			public void onSuccess(String result) {
				if (result.equals(SystemMessage.getMessage(4, 0))) {
					Info.display("", "成功保存");
					menustore.commitChanges();
				} else {
					Info.display("", "保存失败");
				}
			}

		});

	}
}
